(1) Field of the Invention
The present invention relates to a method for storing in a nonvolatile memory and a storage unit and, more particularly, to a method for storing in a nonvolatile memory which can be rewritten by a central processing unit and a storage unit for storing data in a rewritable nonvolatile memory.
(2) Description of the Related Art
Structurally nonvolatile memories, such as flash ROMs and EEPROMs, cannot be written unless data stored in them has been erased by the block or in block before writing data. That is to say, the same method that is used for rewriting data in RAMs cannot be adopted to rewrite data in them. Accordingly, there are drivers which make a user feel as if he/she were accessing a RAM in spite of access to a nonvolatile memory.
These drivers exercise control so that an address specified by an application will correspond on a one-to-one basis to an address in a nonvolatile memory where data can be written. By doing so, a user will feel as if he/she were accessing a RAM.
For example, it is assumed that an application gives instructions to store the data “1” at address A in a nonvolatile memory and that at this time a driver stores the data “1” at address B1 in the nonvolatile memory. Then it is assumed that the application gives instructions to store the data “2” at address A. If data in the nonvolatile memory has not been erased by the block or in block, the data “1” stored at address B1 cannot be rewritten to the data “2.” The driver therefore stores the data “2” at new address B2 in the nonvolatile memory. The driver stores the correspondence between the address specified by the application and the address in the nonvolatile memory where the data was actually stored in the nonvolatile memory. Afterwards, the driver refers to this correspondence between the addresses when it reads the data. By doing so, the correct data can be read.
The writing of data by a driver to a nonvolatile memory will now be described. FIG. 8 is a flow chart showing procedures for the process of writing data performed by a driver. A driver will store data in a nonvolatile memory in accordance with the following procedures.
[Step S51] A driver searches a nonvolatile memory for an area (free area) where data can be written.
[Step S52] The driver writes write start information indicative of the beginning of writing the data into write management information in the nonvolatile memory.
[Step S53] The driver writes the data to the area it searched for in step S51.
[Step S54] The driver writes the correspondence between an address designated by an application to store the data and an address in the nonvolatile memory where the data was actually stored into address management information in the nonvolatile memory.
[Step S55] The driver writes write completion information indicative of the completion of the writing of the data into the write management information.
The driver refers to the correspondence between the addresses in the address management information to read the data the application requests from the nonvolatile memory.
Procedures for the process of rewriting data performed by a driver will now be described. FIG. 9 is a flow chart showing procedures for the process of rewriting data performed by a driver. A driver will rewrite data in a nonvolatile memory in accordance with the following procedures.
[Step S61] A driver searches a nonvolatile memory for an area (free area) where data for rewriting can be written.
[Step S62] The driver writes write start information indicative of the beginning of the writing of the data for rewriting into write management information in the nonvolatile memory.
[Step S63] The driver writes the data for rewriting to the area it searched for in step S61.
[Step S64] The driver writes the correspondence between an address designated by an application to store the data and a new address in the nonvolatile memory where the data for rewriting was actually stored into address management information in the nonvolatile memory.
[Step S65] The driver writes override information into address management information corresponding to data to be rewritten to negate the correspondence between addresses regarding the data to be rewritten.
[Step S66] The driver writes deletion completion information for negating (deleting) the data to be rewritten into the write management information.
[Step S67] The driver writes write completion information indicative of the completion of the writing of the data for rewriting into the write management information.
As stated above, by storing the address management information, the driver can also read the data for rewriting from the nonvolatile memory.
Procedures for a garbage collection process will now be described. FIG. 10 is a flow chart showing procedures for a garbage collection process performed by a driver. A driver will perform garbage collection in a nonvolatile memory in accordance with the following procedures.
[Step S71] A driver selects a copy source unit (this unit means an erase unit).
[Step S72] The driver writes copy start information to a header area in a copy destination unit which will become a spare unit.
[Step S73] The driver copies valid data in the copy source unit to the copy destination unit. This valid data means data which is not included in the deleted data described in step S66 in FIG. 9.
[Step S74] The driver writes copy completion information indicative of the completion of copying to the header area in the copy destination unit.
[Step S75] The driver writes deletion completion information for negating (deleting) the copy source unit to a header area in the copy source unit.
[Step S76] The driver erases data in the copy source unit. As a result, new data can be written to the copy source unit.
[Step S77] The driver writes header information to the header area in the copy source unit.
As stated above, the driver performs garbage collection, writing information to the header areas in the copy source unit and the copy destination unit.
It is assumed that the supply of power is shut off in the middle of a driver performing the above process of writing data to a nonvolatile memory and then returns to normal. The driver refers to information, which is stored in the nonvolatile memory and which indicates the beginning and completion of writing the data, to judge whether the data written is reliable. If information indicative of the completion of the writing of the data is not stored, then the driver will perform the restoration process of writing the data again.
In addition, a method for storing comprising the steps of detecting a factor in interruption of writing data, adding data to this data according to the factor in the interruption, and determining the scope of reliable data is disclosed (see, for example, Japanese Unexamined Patent Publication No. 2000-132464, p.4 and FIG. 1).
However, if the supply of power is shut off in the middle of information (storage management information) regarding the correspondence between an address designated by an application and an address in a nonvolatile memory where data was actually stored being written and then returns to normal, the subsequent data restoration process may be performed on the basis of erroneous storage management information.